// pages/introduce/introduce.js
const App = getApp()
Page({
  data: {
    agree: false,
    detail: {},
    id: "",
    showAll: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    if (!options.id) return
    this.getDetail(options.id)
  },
  getDetail: async function (id) {
    let codeList = [1011, 1012, 1013, 1047, 1048, 1049, 1124, 1125, 1126, 1150]
    let code = codeList.includes(wx.getLaunchOptionsSync().scene)
    let data
    if (code) {
      data = await App.$axios.request({
        url: `/parent/curriculum/vipOrder/${id}`,
        method: 'GET',
        loading: true,
      })
    } else {
      data = await App.$axios.request({
        url: `/parent/curriculum/vip/${id}`,
        method: 'GET',
        loading: true,
      })
    }
    this.setData({
      id: id,
      detail: data
    })
  },
  changeInfoBox() {
    this.setData({
      showAll: !this.data.showAll
    })
  },
  checkboxChange(item) {
    // 同意框
    this.setData({
      agree: !item.currentTarget.dataset.agree
    })
  },
  pay: async function () {
    // 立即支付
    if (!this.data.agree) {
      wx.showToast({
        title: "请先确认须知！",
        icon: "error",
        duration: 2000
      })
      return
    }
    let codeList = [1011, 1012, 1013, 1047, 1048, 1049, 1124, 1125, 1126, 1150]
    let code = codeList.includes(wx.getLaunchOptionsSync().scene)
    let data = await App.$axios.request({
      url: "/parent/order/curriculum/buyOrder",
      data: {
        dataId: this.data.detail.id,
        dataType: code ? 2 : 1,
      },
      method: 'POST',
      loading: true,
    })
    if (data) {
      wx.navigateTo({
        url: `/pages/pay/pay?orderNum=${data.orderNum}&nonceStr=${data.nonce_str}&timeStamp=${data.timeStamp}&timeStamp=${data.timeStamp}&signType=${data.signType}&package=${data.prepay_id}&paySign=${data.sign}`,
      })
    }
  }
})